package cn.lhl.task;

import cn.lhl.constant.Log_Home;
import cn.lhl.sys.event.MyEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;

//@Component

@Slf4j
public class TaskDemo {



	@Scheduled(cron = "0/1 * * * * *")
	public void synTask() {
		sleep();
		//System.out.println(Thread.currentThread().getName() + " syn-task 执行,当前时间: " + LocalDateTime.now());
		Log_Home.springframework.info("123hghhhaha哈哈哈哈");
		Log_Home.springframework.info(" syn-task 执行,当前时间: " + LocalDateTime.now());
		//Log_Home.springframework.info(Marker.ANY_MARKER);
		log.info("log_________");

	}

	@Async
	@Scheduled(cron = "0/1 * * * * *")
	public void asyncTask() {
		sleep();
		//System.out.println(Thread.currentThread().getName() + " async-task 执行,当前时间: " + LocalDateTime.now());
		Log_Home.springframework.info(LocalDateTime.now().toString());
		log.info("log________hh_");
	}


	@Autowired
	private ApplicationEventPublisher applicationEventPublisher;
	@Scheduled(cron = "0/1 * * * * *")
	public void EventTask() {
		MyEvent myEvent = new MyEvent("333", "123");
		applicationEventPublisher.publishEvent(myEvent);
	}


	private void sleep() {
		try {
			Thread.sleep(10 * 1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}
